﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {
 
    public class TestSampleStep {

        /**
          * Step補間、Constantリピートのテスト
          * */
        [Fact]
        public void TestStepConstant () {
            var kseq = new KeyframeSequence (4, 1, KeyframeSequence.Step);
            kseq.RepeatMode = KeyframeSequence.Constant;
            kseq.Duration = 500;

            //                   time             value
            kseq.SetKeyframe (0, 100, new float[] { 1.0f });
            kseq.SetKeyframe (1, 200, new float[] { 2.0f });
            kseq.SetKeyframe (2, 300, new float[] { 3.0f });
            kseq.SetKeyframe (3, 400, new float[] { 4.0f });

            Assert.Equal (1.0f, kseq.Sample (-700, 0));
            Assert.Equal (1.0f, kseq.Sample (50, 0));
            Assert.Equal (1.0f, kseq.Sample (100, 0));
            Assert.Equal (1.0f, kseq.Sample (150, 0));
            Assert.Equal (2.0f, kseq.Sample (200, 0));
            Assert.Equal (2.0f, kseq.Sample (250, 0));
            Assert.Equal (3.0f, kseq.Sample (300, 0));
            Assert.Equal (3.0f, kseq.Sample (350, 0));
            Assert.Equal (4.0f, kseq.Sample (400, 0));
            Assert.Equal (4.0f, kseq.Sample (450, 0));
            Assert.Equal (4.0f, kseq.Sample (700, 0));
        }

        /**
         * Step補間、Loopリピートのテスト
         * */
        [Fact]
           public void TestStepLoop () {
               var kseq = new KeyframeSequence (4, 1, KeyframeSequence.Step);
               kseq.RepeatMode = KeyframeSequence.Loop;
               kseq.Duration = 500;

               //                   time             value
               kseq.SetKeyframe (0, 100, new float[] { 1.0f });
               kseq.SetKeyframe (1, 200, new float[] { 2.0f });
               kseq.SetKeyframe (2, 300, new float[] { 3.0f });
               kseq.SetKeyframe (3, 400, new float[] { 4.0f });

               Assert.Equal (4.0f, kseq.Sample (-1050, 0));
               Assert.Equal (2.0f, kseq.Sample (-250, 0));
               Assert.Equal (4.0f, kseq.Sample (50, 0));
               Assert.Equal (2.0f, kseq.Sample (250, 0));
               Assert.Equal (4.0f, kseq.Sample (550, 0));
               Assert.Equal (2.0f, kseq.Sample (750, 0));
               Assert.Equal (4.0f, kseq.Sample (1050, 0));
           }

    
    }
}
